<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport"  content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <title>{$shmc}-快速付款</title>
    <script src="__STATIC_URL__/static/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
    <script>
        wx.config({
            debug: false,
            appId: "{$jssdk['appid']}",
            timestamp: "{$jssdk['timestamp']}",
            nonceStr: "{$jssdk['nonceStr']}",
            signature: "{$jssdk['signature']}",
            jsApiList: [
                // 所有要调用的 API 都要加到这个列表中

                'hideAllNonBaseMenuItem',

            ]
        });
        wx.ready(function () {
            wx.hideAllNonBaseMenuItem();

        })
    </script>
    <link rel="stylesheet" href="__PUBLIC__/Css/pay.css?id=9"/>

    <script type="text/javascript" src="__PUBLIC__/Js/keyboard.js?v=3"></script>
    <script language="javascript">
        var sdata;
        function getorder() {
            var id = {$id};
            $.ajax({
                type: "POST",
                url: "__CONTROLLER__/getorder2",

                cache: false,
                async: false,
                data: {
                    id: id
                },


                success: function (data) {
                    $('#orderid').val(data);

                }
            });

        }
        function zf() {
            getorder();
            var price = $('#price').val();
            if (price < 0.01) {
                alert('金额不能小于0.01元');
                $('#price').focus();
            } else if (price > 20000) {
                alert('超过最大支付限额');
                $('#price').focus();
            }

            else {
                $("#submit").removeClass("submit");
                $("#submit").addClass("submita");
                $('#submit').attr('onclick', '()');
                $('#submit').val('正在处理中...');
                $.ajax({
                    type: "POST",
                    url: "__CONTROLLER__/pay2/id/{$id}",

                    cache: false,
                    dataType: "json",
                    async: false,
                    data: $('#tab').serialize(),

                    success: function (data) {
                        console.log(data);
                        if (data === 1) {
                            alert('网络超时请重新支付');
                            getorder();
                            $("#submit").removeClass("submita");
                            $("#submit").addClass("submit");
                            $('#submit').attr('onclick', 'zf()');
                            $('#submit').val('重新支付');

                        } else {
                            sdata = data;


                            if (typeof WeixinJSBridge == "undefined") {
                                if (document.addEventListener) {
                                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                                } else if (document.attachEvent) {
                                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                                }
                            } else {
                                onBridgeReady(data);
                            }
                        }

                    }
                });

            }
        }

        function onBridgeReady(data) {
            console.log(data);
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                data,
                function (res) {
                    WeixinJSBridge.log(res.err_msg);
                    if (res.err_msg === 'get_brand_wcpay_request:ok') {

                        paysuccess();

                    } else {
                        getorder();
                        $("#submit").removeClass("submita");
                        $("#submit").addClass("submit");
                        $('#submit').attr('onclick', 'zf()');
                        $('#submit').val('重新支付');

                    }

                });
        }

        function paysuccess() {
            var ordid = $('#orderid').val();
            $.ajax({
                type: "POST",
                url: "__CONTROLLER__/payover/id/{$id}/orderid/" + ordid,

                cache: false,
                dataType: "json",
                async: false,
                data: {},

                success: function (data) {
                    if (data === 0) {

                        window.location.replace("__CONTROLLER__/orderinfo/id/{$id}/orderid/" + ordid);
                    } else {

                        alert('支付失败');
                    }
                    ////
                }


            });

        }
    </script>
</head>
<body>

<div class="zt">
    <div class="zw"></div>
    <div style="width: 100%;text-align: center">
        <div class="logo"><img src="{$headimg}"></div>
    </div>
    <div class="zw"></div>
    <div class="cardexplain">

        <ul class="round">

            <li class="nob">
                <table>

                    <tr>
                        <td>
                            <form role="form" id="tab">
                                <div class="form-group">
                                    <span id="ti">金额(元)</span>
                                    <label for="name"><span class="span">￥</span></label>
                                    <input type="text" class="form-control" id="price" name="price"
                                           oninput="if(value.length>5)value=value.slice(0,5)" readonly="readonly">
                                    <input type="hidden" name="openid" id="openid" value="{$openid}"/>
                                    <input type="hidden" name="orderid" id="orderid" value=""/>
                                </div>
                            </form>
                        <td>
                    </tr>
                </table>


        </ul>
    </div>


    <div class="foots"><span>支付完成后，如需退款请及时联系店员</span></div>

    <div class="footer">

        <!--<span>华意科技提供技术支持</span>-->
    </div>
    <div style="clean:both"></div>
</div>
<script>
    (function () {
        var input1 = document.getElementById('price');


        new KeyBoard(input1);

        input1.onclick = function () {
            new KeyBoard(input1);
        };
    })();
</script>
</body>
</html>